package com.fsoft.tinhcd.app;

import java.io.File;
import java.util.ArrayList;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.hibernate.Query;
import org.hibernate.Session;

import com.fsoft.tinhcd.entity.Region;
import com.fsoft.tinhcd.util.HibernateUtil;

public class App {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		ArrayList<Region> regions = new ArrayList<Region>();
		Query query = session.createQuery("from Region");
		regions = (ArrayList<Region>) query.list();
		try {
			JAXBContext context = JAXBContext.newInstance(Region.class);
			Marshaller marshaller = context.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
					Boolean.TRUE);
			// write to file
			marshaller.marshal(regions.get(0), new File("./Regions.xml"));
		} catch (JAXBException e) {
			e.printStackTrace();
		}
	}

}
